package com.api.shopapi.mapper;


import com.api.shopapi.entity.GoodsAttribute;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface GoodsAttributeMapper {

    @Insert("insert into goods_attribute values " +
            "(#{goodsAttribute.GoodsAttributeCode},#{goodsAttribute.Code},#{goodsAttribute.Name},#{goodsAttribute.Status})")
    int insert(@Param("goodsAttribute") GoodsAttribute goodsAttribute);


    @Update("update goods_attribute goods_attribute set Status=2 " +
            "where GoodsAttributeCode=#{goodsAttributeCode}")
    int delete(@Param("goodsAttributeCode") String goodsAttributeCode);

    @Update("update goods_attribute set " +
            "Code=#{goodsAttribute.Code},Name=#{goodsAttribute.Name},Status=#{goodsAttribute.Status} " +
            "where GoodsAttributeCode=#{goodsAttribute.GoodsAttributeCode}")
    int update(@Param("goodsAttribute") GoodsAttribute goodsAttribute);

    @Select("select * from goods_attribute where GoodsAttributeCode=#{goodsAttributeCode}  limit 1")
    GoodsAttribute getByGoodsAttributeCode(@Param("goodsAttributeCode") String goodsAttributeCode);

    @Select("select * from goods_attribute where Name=#{name} and Status=1 limit 1")
    GoodsAttribute getByName(@Param("name") String name);

    @Select("select * from goods_attribute where Status=1")
    List<GoodsAttribute> getList();

    @Select("<script>" +
            "select * from goods_attribute where 1=1 " +
            "<if test ='name !=null and name!=\"\" '>" +
            " and Name like concat('%',#{name},'%') " +
            "</if>" +
            "<if test ='status!=-1 '>" +
            " and Status=#{status} " +
            "</if>" +
            "</script>")
    List<GoodsAttribute> getPageList(@Param("name")String name,@Param("status") int status);


}
